Skip to content

Conversation

@Ansonhkg
Copy link
Collaborator

@Ansonhkg Ansonhkg commented Oct 18, 2025

WHAT

  • switch the constants mapper to load datil/datil-dev/datil-test ABIs from the scoped @lit-protocol/contracts export map (legacy root import left commented for reference)
  • add verify-contracts-bundle.sh script to inspect bundle size for constants and contracts-sdk pcakges for browser + node targets

Also see: #962 (comment)

TEST

NPM

A snapshot has been published to @lit-protocol/[email protected]

Test repo: https://github.com/LIT-Protocol/pr-962-bundle-size-test

Before

https://test-962-contracts-sdk-bundle-size.vercel.app/bundle-report-lit-sdk.html

image

After

https://test-962-contracts-sdk-bundle-size.vercel.app/bundle-report-contracts-sdk-new.html

image

Locally

./verify-contracts-bundle.sh

BEFORE

import { datil, datilDev, datilTest } from '@lit-protocol/contracts';
⭐️ @lit-protocol/constants bundles:

  Browser includes:
    (Every line below lists a bundled @lit-protocol/contracts file and its raw size)
    node_modules/@lit-protocol/contracts/dist/dev/datil.js -> 352.55 KiB
    node_modules/@lit-protocol/contracts/dist/dev/datil-dev.js -> 352.60 KiB
    node_modules/@lit-protocol/contracts/dist/dev/datil-test.js -> 370.70 KiB
    node_modules/@lit-protocol/contracts/dist/dev/cayenne.js -> 352.37 KiB
    node_modules/@lit-protocol/contracts/dist/dev/habanero.js -> 352.59 KiB
    node_modules/@lit-protocol/contracts/dist/dev/internalDev.js -> 352.63 KiB
    node_modules/@lit-protocol/contracts/dist/dev/manzano.js -> 352.58 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil.js -> 338.55 KiB
    node_modules/@lit-protocol/contracts/dist/prod/cayenne.js -> 338.36 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-dev.js -> 338.60 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-test.js -> 356.70 KiB
    node_modules/@lit-protocol/contracts/dist/prod/habanero.js -> 338.58 KiB
    node_modules/@lit-protocol/contracts/dist/prod/internalDev.js -> 338.63 KiB
    node_modules/@lit-protocol/contracts/dist/prod/manzano.js -> 338.57 KiB
    node_modules/@lit-protocol/contracts/dist/index.js -> 0.74 KiB
    Total -> 4.760 MiB
    (Total reflects the sum of those files before compression/minification)

  Node includes:
    (Every line below lists a bundled @lit-protocol/contracts file and its raw size)
    node_modules/@lit-protocol/contracts/dist/dev/datil.js -> 352.55 KiB
    node_modules/@lit-protocol/contracts/dist/dev/datil-dev.js -> 352.60 KiB
    node_modules/@lit-protocol/contracts/dist/dev/datil-test.js -> 370.70 KiB
    node_modules/@lit-protocol/contracts/dist/dev/cayenne.js -> 352.37 KiB
    node_modules/@lit-protocol/contracts/dist/dev/habanero.js -> 352.59 KiB
    node_modules/@lit-protocol/contracts/dist/dev/internalDev.js -> 352.63 KiB
    node_modules/@lit-protocol/contracts/dist/dev/manzano.js -> 352.58 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil.js -> 338.55 KiB
    node_modules/@lit-protocol/contracts/dist/prod/cayenne.js -> 338.36 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-dev.js -> 338.60 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-test.js -> 356.70 KiB
    node_modules/@lit-protocol/contracts/dist/prod/habanero.js -> 338.58 KiB
    node_modules/@lit-protocol/contracts/dist/prod/internalDev.js -> 338.63 KiB
    node_modules/@lit-protocol/contracts/dist/prod/manzano.js -> 338.57 KiB
    node_modules/@lit-protocol/contracts/dist/index.js -> 0.74 KiB
    Total -> 4.760 MiB
    (Total reflects the sum of those files before compression/minification)

⭐️ @lit-protocol/contracts-sdk bundles:

  Browser includes:
    (Every line below lists a bundled @lit-protocol/contracts file and its raw size)
    node_modules/@lit-protocol/contracts/dist/dev/datil.js -> 352.55 KiB
    node_modules/@lit-protocol/contracts/dist/dev/datil-dev.js -> 352.60 KiB
    node_modules/@lit-protocol/contracts/dist/dev/datil-test.js -> 370.70 KiB
    node_modules/@lit-protocol/contracts/dist/dev/cayenne.js -> 352.37 KiB
    node_modules/@lit-protocol/contracts/dist/dev/habanero.js -> 352.59 KiB
    node_modules/@lit-protocol/contracts/dist/dev/internalDev.js -> 352.63 KiB
    node_modules/@lit-protocol/contracts/dist/dev/manzano.js -> 352.58 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil.js -> 338.55 KiB
    node_modules/@lit-protocol/contracts/dist/prod/cayenne.js -> 338.36 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-dev.js -> 338.60 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-test.js -> 356.70 KiB
    node_modules/@lit-protocol/contracts/dist/prod/habanero.js -> 338.58 KiB
    node_modules/@lit-protocol/contracts/dist/prod/internalDev.js -> 338.63 KiB
    node_modules/@lit-protocol/contracts/dist/prod/manzano.js -> 338.57 KiB
    node_modules/@lit-protocol/contracts/dist/index.js -> 0.74 KiB
    Total -> 4.760 MiB
    (Total reflects the sum of those files before compression/minification)

  Node includes:
    (Every line below lists a bundled @lit-protocol/contracts file and its raw size)
    node_modules/@lit-protocol/contracts/dist/dev/datil.js -> 352.55 KiB
    node_modules/@lit-protocol/contracts/dist/dev/datil-dev.js -> 352.60 KiB
    node_modules/@lit-protocol/contracts/dist/dev/datil-test.js -> 370.70 KiB
    node_modules/@lit-protocol/contracts/dist/dev/cayenne.js -> 352.37 KiB
    node_modules/@lit-protocol/contracts/dist/dev/habanero.js -> 352.59 KiB
    node_modules/@lit-protocol/contracts/dist/dev/internalDev.js -> 352.63 KiB
    node_modules/@lit-protocol/contracts/dist/dev/manzano.js -> 352.58 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil.js -> 338.55 KiB
    node_modules/@lit-protocol/contracts/dist/prod/cayenne.js -> 338.36 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-dev.js -> 338.60 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-test.js -> 356.70 KiB
    node_modules/@lit-protocol/contracts/dist/prod/habanero.js -> 338.58 KiB
    node_modules/@lit-protocol/contracts/dist/prod/internalDev.js -> 338.63 KiB
    node_modules/@lit-protocol/contracts/dist/prod/manzano.js -> 338.57 KiB
    node_modules/@lit-protocol/contracts/dist/index.js -> 0.74 KiB
    Total -> 4.760 MiB
    (Total reflects the sum of those files before compression/minification)

Artifacts written to /Users/anson/Projects/datil-sdk/tmp/bundle-test

AFTER

// @ts-ignore -- TypeScript can't resolve the subpath because this package compiles to CJS, but runtime bundlers can.
import { datil as datilContext } from '@lit-protocol/contracts/prod/datil.js';
// @ts-ignore -- see note above.
import { datilDev as datilDevContext } from '@lit-protocol/contracts/prod/datil-dev.js';
// @ts-ignore -- see note above.
import { datilTest as datilTestContext } from '@lit-protocol/contracts/prod/datil-test.js';
⭐️ @lit-protocol/constants bundles:

  Browser includes:
    (Every line below lists a bundled @lit-protocol/contracts file and its raw size)
    node_modules/@lit-protocol/contracts/dist/prod/datil.js -> 338.55 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-dev.js -> 338.60 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-test.js -> 356.70 KiB
    Total -> 1.010 MiB
    (Total reflects the sum of those files before compression/minification)

  Node includes:
    (Every line below lists a bundled @lit-protocol/contracts file and its raw size)
    node_modules/@lit-protocol/contracts/dist/prod/datil.js -> 338.55 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-dev.js -> 338.60 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-test.js -> 356.70 KiB
    Total -> 1.010 MiB
    (Total reflects the sum of those files before compression/minification)

⭐️ @lit-protocol/contracts-sdk bundles:

  Browser includes:
    (Every line below lists a bundled @lit-protocol/contracts file and its raw size)
    node_modules/@lit-protocol/contracts/dist/prod/datil.js -> 338.55 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-dev.js -> 338.60 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-test.js -> 356.70 KiB
    Total -> 1.010 MiB
    (Total reflects the sum of those files before compression/minification)

  Node includes:
    (Every line below lists a bundled @lit-protocol/contracts file and its raw size)
    node_modules/@lit-protocol/contracts/dist/prod/datil.js -> 338.55 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-dev.js -> 338.60 KiB
    node_modules/@lit-protocol/contracts/dist/prod/datil-test.js -> 356.70 KiB
    Total -> 1.010 MiB
    (Total reflects the sum of those files before compression/minification)

Artifacts written to /Users/anson/Projects/datil-sdk/tmp/bundle-test

Copilot AI review requested due to automatic review settings October 18, 2025 01:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors contract ABI imports to use scoped subpath exports from @lit-protocol/contracts instead of the root package import, reducing bundle sizes by only including necessary network artifacts (datil/datil-dev/datil-test). A verification script is added to validate that bundles contain only the intended contract artifacts.

Key changes:

  • Switched from root @lit-protocol/contracts import to scoped subpath imports for specific networks
  • Added bundle verification script to audit included contract artifacts
  • Removed caret from contracts dependency version for stricter version control

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
verify-contracts-bundle.sh New script that bundles test entries for constants and contracts-sdk packages, then analyzes which contract artifacts are included
packages/constants/src/lib/constants/mappers.ts Refactored to import network-specific contract contexts via subpath exports instead of root import
package.json Changed @lit-protocol/contracts dependency from ^0.0.74 to 0.0.74 (removed caret)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +9 to +22
import { datil as datilContext } from '@lit-protocol/contracts/prod/datil.js';
// @ts-ignore -- see note above.
import { datilDev as datilDevContext } from '@lit-protocol/contracts/prod/datil-dev.js';
// @ts-ignore -- see note above.
import { datilTest as datilTestContext } from '@lit-protocol/contracts/prod/datil-test.js';

type DatilContext = typeof datilContext;
type DatilDevContext = typeof datilDevContext;
type DatilTestContext = typeof datilTestContext;

const datil: DatilContext = datilContext;
const datilDev: DatilDevContext = datilDevContext;
const datilTest: DatilTestContext = datilTestContext;

Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These re-assignments from imported contexts to new constants appear unnecessary. The imports could be renamed directly using import { datil as datilContext } from ... and then used as datilContext throughout the code, or imported as datil directly to maintain the existing variable names. The current approach adds extra indirection without clear benefit.

Suggested change
import { datil as datilContext } from '@lit-protocol/contracts/prod/datil.js';
// @ts-ignore -- see note above.
import { datilDev as datilDevContext } from '@lit-protocol/contracts/prod/datil-dev.js';
// @ts-ignore -- see note above.
import { datilTest as datilTestContext } from '@lit-protocol/contracts/prod/datil-test.js';
type DatilContext = typeof datilContext;
type DatilDevContext = typeof datilDevContext;
type DatilTestContext = typeof datilTestContext;
const datil: DatilContext = datilContext;
const datilDev: DatilDevContext = datilDevContext;
const datilTest: DatilTestContext = datilTestContext;
import { datil } from '@lit-protocol/contracts/prod/datil.js';
// @ts-ignore -- see note above.
import { datilDev } from '@lit-protocol/contracts/prod/datil-dev.js';
// @ts-ignore -- see note above.
import { datilTest } from '@lit-protocol/contracts/prod/datil-test.js';

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like you prob need the typedefs here, and copilot is wrong?

@Ansonhkg Ansonhkg marked this pull request as draft October 18, 2025 01:54
@Ansonhkg Ansonhkg self-assigned this Oct 18, 2025
@Ansonhkg Ansonhkg requested a review from glitch003 October 18, 2025 02:06
@Ansonhkg Ansonhkg marked this pull request as ready for review October 18, 2025 02:07
@Ansonhkg Ansonhkg added ✨ Enhancement New feature or request v7 | Datil labels Oct 18, 2025
Copy link
Collaborator

@glitch003 glitch003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very excited to see this!! thx for getting this in @Ansonhkg - will be a big improvement for devs. up to you if you wanna implement any of the copilot changes or not. the only one i saw that might make sense is https://github.com/LIT-Protocol/js-sdk/pull/963/files#r2441514234 but i don't think it really matters, just might be a little cleaner, but whatevs

Copy link
Contributor

@MaximusHaximus MaximusHaximus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 this is a great improvement for code that does need the contracts-sdk (thus needs the ABIs) -- but it's not what the original goal was, and it still leaves 1MB of ABIs in the constants package for consumers who just import the constants package to get stuff like our LIT_CHAINS definitions, even though they don't need to use the ABIs. :)

The only consumer of the ABIs is the contracts-sdk, so moving the mapping into the contracts-sdk allowed us to eliminate all of the ABIs from simple consumers of the constants package. This is good because we often need constants in our LIT actions, but really don't want to bundle any of the LIT standard ABIs into the LIT action unless we actually need them 👍

The idea with this change was to eliminate any ABIs from being part of our core constants package at all, thus the ticket title of "move our contract ABIs our of the constants package", and the ticket description, and which is the PR title too, but this doesn't actually do...this change set is more like 'Don't import totally unused ABIs into the constants package' , which is still a great optimization, but not quite what we were looking for :). I think that we should mark this change as done under a different ticket so we don't lose track of the original goal of JSS-78 👍 We're up against LIT action size constraints in a major way w/ vincent actions so saving the other 1MB of ABIs that this leaves in the constants package would be a huge win 👍 :)

To recap, the idea is:

  • If someone just needs @lit-protocol/constants, they don't get any ABI mapping 🎉
  • If someone needs the contracts-sdk, then they will get the ABIs along with the contracts-sdk code...because they are a hard dependency requirement for the contracts-sdk :)
  • If someone wants JUST the ABIs they can import them directly from @lit-protocol/contracts :)

// import { datil, datilDev, datilTest } from '@lit-protocol/contracts';

// @ts-ignore -- TypeScript can't resolve the subpath because this package compiles to CJS, but runtime bundlers can.
import { datil as datilContext } from '@lit-protocol/contracts/prod/datil.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just be able to import this without the .js extension and have TS detect the types properly 🤔
TS >4.9 uses the exports paths to find appropriate types 🤔
You might need to remove the barrel file from the root index.ts entirely 👍
We should also go ahead and remove the typingVersions export since our supported versions at this point is high enough that the exports key is what should be used anyway 👍 :)

@Ansonhkg Ansonhkg merged commit 5247ea3 into master Oct 29, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ Enhancement New feature or request v7 | Datil

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants